/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.AdminDao;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/als")
public class AdminLoginServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id=req.getParameter("pname");
        String password=req.getParameter("passname");
        Boolean bool=new AdminDao().Login(id,password);
        if(bool==true){
            HttpSession session=req.getSession();
            session.setAttribute("adminLogin", "Y");
            resp.sendRedirect("Admin.jsp");
        }
        else{
            resp.setContentType("text/html;charset=utf-8");
            resp.getWriter().println("<script language='javascript'>alert('账号或密码错误！');window.location.href='AdminLogin.jsp';</script>");
            resp.getWriter().println("<a href='AdminLogin.jsp'>返回登录界面</a>");
        }
    }
    
}
